package lesson10;

import javax.swing.*;
import java.awt.*;

public class TestFrame01 extends JFrame {
    private Image logoImg = new ImageIcon("images/logo.png").getImage();
    private Image bgImg = new ImageIcon("images/timg.jpg").getImage();
    private Font font = new Font("黑体",Font.PLAIN,30);
    private Color color = new Color(223,147,32);
    private JButton btn1 = new JButton("按钮1");
    private JButton btn2 = new JButton("按钮2");
    private JLabel userLabel = new JLabel("用户名：");
    private JLabel pwdLabel = new JLabel("密码：");
    private JTextField userField = new JTextField();
    private JPasswordField pwdField = new JPasswordField();
    /** 多行文本 */
    private JTextArea infoTextArea = new JTextArea();
    /** 下拉列表 */
    private JComboBox cityComboBox = new JComboBox(new String[]{"成都","上海","深圳","北京"});
    /** 多选列表 */
    private JList languageList = new JList(new String[]{"Java基础","JavaOO","JavaWeb"});
    public TestFrame01(){
        // 通过绘制的方法将背景绘制在JFrame的ContentPane上面
        this.setContentPane(new JPanel(){
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgImg,0,0,800,600,this);
            }
        });
        // 设置容器面板布局方式为空布局
        this.setLayout(null);
        btn1.setBounds(10,10,100,50);
        btn2.setBounds(120,10,100,50);

        userLabel.setBounds(10,70,150,50);
        userLabel.setFont(font);
        userLabel.setForeground(Color.magenta);

        userField.setBounds(170,70,200,50);

        pwdLabel.setBounds(10,130,150,50);
        pwdLabel.setFont(font);
        pwdLabel.setForeground(Color.magenta);

        pwdField.setBounds(170,130,200,50);

        infoTextArea.setBounds(10,190,200,200);

        cityComboBox.setBounds(10,400,150,25);

        languageList.setBounds(10,435,200,150);
        this.add(btn1);
        this.add(btn2);
        this.add(userLabel);
        this.add(userField);
        this.add(pwdLabel);
        this.add(pwdField);
        this.add(infoTextArea);
        this.add(cityComboBox);
        this.add(languageList);
        // 设置窗口大小
        this.setSize(800,600);
        // 设置窗口标题
        this.setTitle("测试窗口");
        // 设置窗口图片
        this.setIconImage(logoImg);
        // 将窗口默认显示在屏幕的正中
        this.setLocationRelativeTo(null);
        // 设置窗口关闭策略：关闭窗口即结束程序
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        // 将窗口设置为可显状态
        this.setVisible(true);
    }

    public static void main(String[] args) {
        new TestFrame01();
    }
}
